<template>
  <div>
    <TopFilter :list="topFilterList" :cols="4" :rows="6" :collapse="true" :labelWidth="100" @filterChange="getBusiness" @onCollapse="collapseHandle"> </TopFilter>
    <!-- <ButtonArea align="right" :style="{ paddingLeft: '0px', paddingRight: '0px', margin: '0 auto', textAlign: 'center' }"> -->
    <!-- <el-button size="small" type="primary" @click="orderClick">工单解锁</el-button> -->
    <!-- <el-button size="small" type="primary" @click="orderLogClick">查看日志</el-button> -->
    <!-- </ButtonArea> -->

    <p>在修天数：竣工时间减去开单时间 在修天数5-9天：黄色 大于10天：浅红色</p>
    <FilterTable
      ref="businessMangerTable"
      columnsRef="repair_repairReception_repairBusinessManager_main"
      :columns="columns"
      selectionType="single"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :uidkey="'id'"
      :rowstyles="styleList"
      :cellstyles="fetchRowstyles"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="columns => (this.selectColumns = columns)"
      :onSyncTableData="syncDataChange"
    >
      <template slot="controls">
        <AjaxButton v-show="btnExportType" size="small" type="primary" :click="repairBusinessExport">导出</AjaxButton>
      </template>
    </FilterTable>

    <!-- 查询明细 -->
    <Drawer :visible.sync="labour" title="明细" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <labourModel :list="selectData" :repairParams="repairParams" @closeDialog="closeDialog"></labourModel>
    </Drawer>

    <!-- 查看日志 -->
    <BaseDialog :visible.sync="orderLog" title="工单日志信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <orderLogModel :list="this.selectColumns" @closeOrderLog="closeOrderLog"></orderLogModel>
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
import _ from 'lodash';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import { exportExcelFile } from '@/utils/index';
import { getPinpSelect, getChexSelect, getCheModelSelect } from '@/api/repair/repairReception/customer/brand.js';
import { queryRepairBusiness, unLockRepairOrder, repairBussinessExportExcel, menuUserAction, repairBusinessExport } from '@/api/repair/repairReception/repairBusinessManger';
import labourModel from '@/pages/repair/repairReception/repairBusinessManger/labourModel';
import orderLogModel from '@/pages/repair/repairReception/repairBusinessManger/orderLogModel';
import { getProvince, getCitys, getDistrict } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getBrand, getSeries, getModel, getRegion, getBxgsSelect } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getWxlxSelect, getSystemDefault } from '@/api/repair/repairReception/customer';
import { getAllUser } from '@/api/part/common';
import { queryBlalanceInfo } from '@/api/repair/repairReception/repairBusinessManger';
import { findAllRepair } from '@/api/repair/basicParameters';
import { getAppId } from '@/assets/js/auth';

export default {
  name: 'businessManger',
  components: {
    labourModel,
    orderLogModel
  },
  mixins: [dictionary],
  data() {
    this.isOpenDate = true; // 预计交车
    this.selectData = {};
    return {
      topFilterList: this.createTopFilters(),
      selectColumns: [],
      columns: this.createTableColumns(),
      recallList: [],
      fetchApi: queryRepairBusiness,
      fetchParams: { xhrAbort: true },
      order: false,
      labour: false,
      orderLog: false,
      brandCode: '',
      styleList: [],
      fetchRowstyles: [], // 指定单个样式
      consultantRes: {},
      btnExportType: true,
      systemOptionAuthParams: {
        isCanExportExcel: '10041001' // 是否可以导出excel
      },
      systemDefalutParams: {
        yjcylTime: '', // 预交车预留时间
        orderStatus: '' // 判断是否为一车一单状态
      },
      checkman: [], // 检验员'
      isExportExcel: false, // 是否有导出权限
      repairParams: {} // 服务参数
    };
  },
  computed: {},
  mounted() {
    this.columns = getAppId() == 'arcfox' ? this.createTableColumnsAF() : this.createTableColumns();
    this.menuUserAction();
    this.getBrand();
    this.serviceConsultant();
    // this.getBxgsSelect();
    this.getProvine();
    this.checkSystemOptionAuthParams(); // 页面加载完成校验系统权限参数做相应设置
    this.getWxtypeSelect();
    this.getSystemDefaultValueInfo();
    this.queryAllUser(); // 查询全部人员
    this.queryRepairParams(); // 获取服务参数
  },

  methods: {
    createTopFilters() {
      return [
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo',
          onEnter: () => {
            this.getBusiness();
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '维修类型',
          fieldName: 'repairTypeCode',
          placeholder: '请选择',
          itemList: [],
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'serviceAdvisor',
          placeholder: '请选择',
          itemList: [],
          filterable: true,
          initialValue: ''
        },
        // {
        //   type: 'SELECT',
        //   label: '是否提报索赔',
        //   fieldName: 'isClaimTag',
        //   itemList: this.createDictList(1004)
        // },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brand',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changePinpSelect(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'series',
          placeholder: '请选择',
          itemList: [],
          change: val => {
            this.changeChexSelect(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '车型',
          fieldName: 'model',
          placeholder: '请选择',
          itemList: [],
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主姓名',
          fieldName: 'ownerName',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主编号',
          fieldName: 'ownerNo',
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否竣工',
          fieldName: 'completeTag',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否结清',
          fieldName: 'payOff',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '交车标识',
          fieldName: 'deliveryTag',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'claimNo'
        },
        {
          type: 'SELECT',
          label: '是否含增项',
          fieldName: 'isContainAdd',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          label: '选择时间类型',
          type: 'SELECT',
          fieldName: 'dataType',
          initialValue: 'RO_CREATE_DATE',
          itemList: [
            { value: 'RO_CREATE_DATE', text: '工单开单时间' },
            // { value: 'FOR_BALANCE_TIME', text: '提交结算时间' },
            // { value: 'COMPLETE_TIME', text: '竣工时间' },
            // { value: 'DELIVERY_DATE', text: '交车日期' },
            // { value: 'BALANCE_CLOSE_TIME', text: '关单日期' },
            { value: 'BALANCE_TIME', text: '结算时间' },
            { value: 'END_TIME_SUPPOSED', text: '预交车时间' },
            { value: 'SQUARE_DATE', text: '结清日期' }
            // { value: 'PRINT_RO_TIME', text: '工单打印时间' },
            // { value: 'PRINT_BALANCE_TIME', text: '结算单打印时间' }
          ],
          rules: [{ required: true, message: '请选择时间类型', trigger: 'change' }]
        },
        {
          type: 'RANGE_DATE',
          dateType: 'daterange',
          label: '选择日期',
          fieldName: 'dataBeginDate|dataEndDate',
          initialValue: [
            moment(new Date())
              .subtract(6, 'month')
              .format('YYYY-MM-DD'),
            moment(new Date()).format('YYYY-MM-DD')
          ],
          valueFormat: 'yyyy-MM-dd',
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '保险公司',
          fieldName: 'insuranceCompany',
          placeholder: '请选择',
          itemList: this.createDictList(9607),
          initialValue: ''
        },
        {
          type: 'CHECKBOX',
          fieldName: 'isExtendQuery',
          label: '是否扩展查询',
          initialValue: '',
          change: val => {
            this.exQueryBtnState(val);
          },
          initialValue: '0'
        },
        {
          type: 'INPUT',
          label: '地址',
          fieldName: 'address',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '邮编',
          fieldName: 'zipCode',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: 'E_MAIL',
          fieldName: 'eMail',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '是否索赔',
          fieldName: 'haveClaimTag',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('1004'),
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '省份',
          fieldName: 'PROVINCE',
          placeholder: '请选择',
          disabled: true,
          itemList: [],
          change: val => {
            this.provinceChange(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '城市',
          fieldName: 'CITY',
          placeholder: '请选择',
          disabled: true,
          itemList: [],
          change: val => {
            this.cityChange(val);
          },
          initialValue: ''
        },
        {
          type: 'SELECT',
          label: '区县',
          fieldName: 'DISTRICT',
          placeholder: '请选择',
          disabled: true,
          itemList: [],
          initialValue: ''
        }

        // {
        //   type: 'MULTIPLE_SELECT',
        //   label: '工单状态',
        //   fieldName: 'roStatus',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('8049'),
        //   initialValue: ''
        // },
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   fieldName: 'remark',
        //   placeholder: '请选择',
        //   initialValue: ''
        // }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 110,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.repairLabour(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '工单开单时间',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 130
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 160
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8049'),
          dictItems: this.createDictList('8049')
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        // {
        //   title: '确认方式',
        //   dataIndex: 'CONFIRM_TYPE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '确认状态',
        //   dataIndex: 'CONFIRM_STATUS',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '维修开工时间',
          dataIndex: 'RO_BEGIN_DATE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修时长（分钟）',
          dataIndex: 'REPAIR_TIME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '在修天数',
          dataIndex: 'REPAIR_DAYS',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          editable: false,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '是否提报索赔',
          dataIndex: 'isClaimTag',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        },
        {
          title: '本次进厂是否放弃活动',
          dataIndex: 'IS_GIVE_UP_ACTIVITY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '交车标识',
          dataIndex: 'DELIVER_CAR',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否结清',
          dataIndex: 'PAY_OFF',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否含增项',
          dataIndex: 'IS_ADD',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        // {
        //   title: '指定技师',
        //   dataIndex: 'CHIEF_TECHNICIAN',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   editable: false,
        //   filterItems: [],
        //   editType: 'select',
        //   editItems: []
        // },
        // {
        //   title: '维修技师',
        //   dataIndex: 'TECHNICIAN_UNITE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: [],
        //   editable: false,
        //   filterItems: [],
        //   editType: 'select',
        //   editItems: []
        // },
        {
          title: '结算员',
          dataIndex: 'BALANCE_HANDLER',
          dictItems: [],
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车主编号',
          dataIndex: 'OWNER_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '客户类型',
          dataIndex: 'OWNER_PROPERTY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8011'),
          dictItems: this.createDictList('8011')
        },
        {
          title: '应收维修金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          align: 'right'
        },
        {
          title: '实收维修金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '交车日期',
          dataIndex: 'DELIVER_CAR_TIME',
          sorter: true,
          filter: true,
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          filterType: 'date-range',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '是否竣工',
          dataIndex: 'COMPLETE_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '竣工时间',
          dataIndex: 'COMPLETE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          width: 130,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '是否准时完工',
          dataIndex: 'COMPLETE_ON_TIME',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '进厂行驶里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        // {
        //   title: '出厂行驶里程',
        //   dataIndex: 'OUT_MILEAGE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        {
          title: '预交车时间',
          dataIndex: 'END_TIME_SUPPOSED',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        // {
        //   title: '送修人电话',
        //   dataIndex: 'DELIVERER_PHONE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '送修人手机',
          dataIndex: 'DELIVERER_MOBILE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修人',
          dataIndex: 'DELIVERER',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        // {
        //   title: '工时费',
        //   dataIndex: 'LABOUR_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2,
        //   summation: true,
        //   align: 'right',
        // },
        {
          title: '工时费',
          dataIndex: 'RECEIVEABLE_LABOUR_FEE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '实收工时费',
          dataIndex: 'REAL_LABOUR_FEE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        // {
        //   title: '维修材料费',
        //   dataIndex: 'REPAIR_PART_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2,
        //   summation: true,
        //   align: 'right',
        // },
        {
          title: '维修材料费',
          dataIndex: 'SALE_PAR_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '实收维修材料费',
          dataIndex: 'PAR_REAL_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right'
        },
        {
          title: '实收附加项目费',
          dataIndex: 'ADD_ITEM_REAL_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right'
        },
        {
          title: '结算打印时间',
          dataIndex: 'PRINT_BALANCE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        // {
        //   title: '工单修改次数',
        //   dataIndex: 'fake8',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        {
          title: '故障描述',
          dataIndex: 'RO_TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        // {
        //   title: '上次保养日期',
        //   dataIndex: 'LAST_MAINTENANCE_DATE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'date-range',
        //   exportFormat: {
        //     t: 'd'
        //   }
        // },
        // {
        //   title: '上次保养里程',
        //   dataIndex: 'LAST_MAINTENANCE_MILEAGE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number'
        // },
        // {
        //   title: '车间反馈',
        //   dataIndex: 'EWORKSHOP_REMARK',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '索赔单号',
          dataIndex: 'CLAIM_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险公司',
          dataIndex: 'INSURATION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: this.createDictList(9607)
        },
        {
          title: '是否修改预交车时间',
          dataIndex: 'CHANGE_DELIVER_CAR_TIME',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        },
        {
          title: '车辆销售日期',
          dataIndex: 'SALES_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD',
          exportFormat: {
            t: 'd'
          }
        }

        // {
        //   title: '合计金额',
        //   dataIndex: 'TOTAL_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2,
        //   align: 'right',
        //   summation: true
        // },
        // {
        //   title: '合计税额',
        //   dataIndex: 'TAX_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2,
        //   align: 'right',
        //   summation: true
        // },
        // {
        //   title: '是否关单',
        //   dataIndex: 'BALANCE_CLOSE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   dictItems: this.createDictList('1004')
        // },
        // {
        //   title: '送修人邮箱',
        //   dataIndex: 'DELIVERER_EMAIL',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '提交结算时间',
        //   dataIndex: 'FOR_BALANCE_TIME',
        //   sorter: true,
        //   filter: true,
        //   dateFormat: 'YYYY-MM-DD HH:mm:ss',
        //   filterType: 'date-range',
        //   exportFormat: {
        //     t: 'd'
        //   }
        // },
        // {
        //   title: '是否待信',
        //   dataIndex: 'WAIT_INFO_TAG',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   dictItems: this.createDictList('1004')
        // },
        // {
        //   title: '是否待料',
        //   dataIndex: 'WAIT_PART_TAG',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   dictItems: this.createDictList('1004')
        // },
        // {
        //   title: '销售材料费',
        //   dataIndex: 'SALES_PART_AMOUNT',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'number',
        //   precision: 2,
        //   summation: true,
        //   align: 'right',
        //   render: props => {
        //     return <span>{Number(props.row.SALES_PART_AMOUNT).toFixed(2)}</span>;
        //   }
        // },
        // {
        //   title: '结算时间',
        //   dataIndex: 'BALANCE_TIME',
        //   sorter: true,
        //   filter: true,
        //   width: 150,
        //   filterType: 'date-range',
        //   dateFormat: 'YYYY-MM-DD HH:mm:ss',
        //   exportFormat: {
        //     t: 'd'
        //   }
        // },
        // {
        //   title: '证件号码',
        //   dataIndex: 'CERTIFICATE_NO',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '备注',
        //   dataIndex: 'REMARK',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        // {
        //   title: '电子首保卡备注',
        //   dataIndex: 'REMARK1',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input',
        //   hidden: true
        // },
        // {
        //   title: '是否修改预交车日期',
        //   dataIndex: 'IS_UPDATE_END_TIME_SUPPOSED',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: this.createDictList('1004'),
        //   dictItems: this.createDictList('1004')
        // }
      ];
    },
    createTableColumnsAF() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 110,
          render: props => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.repairLabour(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        {
          title: '工单开单时间',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 130
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          sorter: true,
          filter: true,
          filterType: 'input',
          width: 160
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8049'),
          dictItems: this.createDictList('8049')
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '确认方式',
          dataIndex: 'CONFIRM_TYPE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '确认状态',
          dataIndex: 'CONFIRM_STATUS',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修开工时间',
          dataIndex: 'RO_BEGIN_DATE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '维修时长（分钟）',
          dataIndex: 'REPAIR_TIME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '在修天数',
          dataIndex: 'REPAIR_DAYS',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          sorter: true,
          filter: true,
          editable: false,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: [],
          editType: 'select',
          editItems: []
        },
        {
          title: '极狐汽车服务专员',
          dataIndex: 'XG_NAME',
          sorter: true,
          filter: true,
          editable: false,
          filterType: 'input'
        },
        {
          title: '极狐汽车服务专员电话',
          dataIndex: 'XG_MOBILE',
          sorter: true,
          filter: true,
          editable: false,
          filterType: 'input'
        },
        {
          title: '是否提报索赔',
          dataIndex: 'isClaimTag',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        },
        {
          title: '本次进厂是否放弃活动',
          dataIndex: 'IS_GIVE_UP_ACTIVITY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '交车标识',
          dataIndex: 'DELIVER_CAR',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否结清',
          dataIndex: 'PAY_OFF',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '是否含增项',
          dataIndex: 'IS_ADD',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '结算员',
          dataIndex: 'BALANCE_HANDLER',
          dictItems: [],
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '品牌',
          dataIndex: 'BRAND_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车系',
          dataIndex: 'SERIES_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'MODEL_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '车主编号',
          dataIndex: 'OWNER_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车主',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '客户类型',
          dataIndex: 'OWNER_PROPERTY',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('8011'),
          dictItems: this.createDictList('8011')
        },
        {
          title: '应收维修金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'input',
          precision: 2,
          align: 'right'
        },
        {
          title: '实收维修金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '交车日期',
          dataIndex: 'DELIVER_CAR_TIME',
          sorter: true,
          filter: true,
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          filterType: 'date-range',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '是否竣工',
          dataIndex: 'COMPLETE_TAG',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '竣工时间',
          dataIndex: 'COMPLETE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          width: 130,
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '是否准时完工',
          dataIndex: 'COMPLETE_ON_TIME',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('1004'),
          dictItems: this.createDictList('1004')
        },
        {
          title: '进厂行驶里程',
          dataIndex: 'IN_MILEAGE',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '预交车时间',
          dataIndex: 'END_TIME_SUPPOSED',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '送修人手机',
          dataIndex: 'DELIVERER_MOBILE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '送修人',
          dataIndex: 'DELIVERER',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '工时费',
          dataIndex: 'RECEIVEABLE_LABOUR_FEE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '实收工时费',
          dataIndex: 'REAL_LABOUR_FEE',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '维修材料费',
          dataIndex: 'SALE_PAR_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '实收维修材料费',
          dataIndex: 'PAR_REAL_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          align: 'right',
          summation: true
        },
        {
          title: '附加项目费',
          dataIndex: 'ADD_ITEM_AMOUNT',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right'
        },
        {
          title: '实收附加项目费',
          dataIndex: 'ADD_ITEM_REAL_SUM',
          sorter: true,
          filter: true,
          filterType: 'number',
          precision: 2,
          summation: true,
          align: 'right'
        },
        {
          title: '结算打印时间',
          dataIndex: 'PRINT_BALANCE_TIME',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '故障描述',
          dataIndex: 'RO_TROUBLE_DESC',
          sorter: true,
          filter: true,
          filterType: 'input',
          showOverflowTooltip: true
        },
        {
          title: '索赔单号',
          dataIndex: 'CLAIM_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '保险公司',
          dataIndex: 'INSURATION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input',
          dictItems: this.createDictList(9607)
        },
        {
          title: '是否修改预交车时间',
          dataIndex: 'CHANGE_DELIVER_CAR_TIME',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList(1004),
          dictItems: this.createDictList(1004)
        },
        {
          title: '车辆销售日期',
          dataIndex: 'SALES_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD',
          exportFormat: {
            t: 'd'
          }
        }
      ];
    },
    async menuUserAction() {
      let res = await menuUserAction();
      for (const item of res.data) {
        if (item.actionUrl == '666666') {
          this.isExportExcel = true;
        }
      }
    },

    // 是否启用交车时间
    openRangeDate(val) {
      +val == 1 ? (this.isOpenDate = false) : (this.isOpenDate = true);
      let openDate = this.topFilterList.find(x => x.fieldName === 'checkPreDeliverVehicleBeginDate|checkPreDeliverVehicleEndDate');
      openDate.disabled = this.isOpenDate;
      if (+val == 1) {
        this.isOpenDate = false;
        openDate.disabled = this.isOpenDate;
        openDate.initialValue = [moment().format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')];
      } else {
        this.isOpenDate = true;
        openDate.disabled = this.isOpenDate;
        openDate.initialValue = [];
      }
    },

    // 售前人员接口数据
    async serviceConsultant() {
      let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let technician = { role: dictCode.TECHNICIAN }; // 指定技师
      let CLERK = { role: dictCode.EXAMINATION_CLERK }; // 质检员
      const consultantRes = await searchRoleByCode(consultant);
      const technicianRes = await searchRoleByCodes(technician);
      let man = await searchRoleByCode(CLERK);
      this.checkman = man.data;
      this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').filterItems = this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = consultantRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
      this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').dictItems = this.columns.find(x => x.dataIndex === 'SERVICE_ADVISOR').editItems = consultantRes.data.map(x => ({
        text: x.employeeName,
        value: x.userId + ''
      }));
      // this.columns.find(x => x.dataIndex === 'CHIEF_TECHNICIAN').filterItems = this.columns.find(x => x.dataIndex === 'CHIEF_TECHNICIAN').editItems = technicianRes.data.map(x => ({
      //   text: x.employeeName,
      //   value: x.userId + ''
      // }));
      let allCookie = document.cookie.split(';');
      let user = '';
      allCookie.forEach(x => {
        if (x.indexOf('userId') > -1) {
          user = x.split('=')[1];
        }
      });
      for (const x of consultantRes.data) {
        if (x.userId + '' == user + '') {
          // 因为cookie取回是int值
          this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').initialValue = user + '';
          break; // 取当前服务顾问
        }
      }
    },

    // 获取维修项目类型
    async getWxtypeSelect() {
      const res = await getWxlxSelect();
      this.topFilterList.find(x => x.fieldName === 'repairTypeCode').itemList = res.data.map(x => ({
        value: x.REPAIR_TYPE_CODE,
        text: x.REPAIR_TYPE_NAME
      }));
    },

    // 获取品牌 ——下拉框
    async getBrand() {
      this.topFilterList.find(x => x.fieldName === 'brand').itemList = (await getPinpSelect()).data.map(x => ({ value: x.brandId + '', text: x.brandName }));
    },

    // 车系下拉框
    async getSeries(id) {
      !_.isNil(id) && (this.topFilterList.find(x => x.fieldName === 'series').itemList = (await getChexSelect(id)).data.map(x => ({ value: x.seriesId + '', text: x.seriesName })));
    },

    // 车型下拉框
    async getCheModelSelect(brandCode, id) {
      !_.isNil(id) &&
        (this.topFilterList.find(x => x.fieldName === 'model').itemList = (await getCheModelSelect(brandCode, id)).data.map(x => ({ value: x.modelId + '', text: x.modelName, model: x.modelCode })));
    },

    // 获取保险公司-下拉框
    async getBxgsSelect() {
      const res = await getBxgsSelect();
      this.topFilterList.find(x => x.fieldName === 'insuranceCompany').itemList = res.data.map(x => ({ value: x.INSURATION_CODE, text: x.INSURATION_NAME }));
    },

    // 品牌下拉框改变时
    changePinpSelect(id) {
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'series'));
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'model'));
      this.brandCode = id;
      if (!id) return;
      this.getSeries(id);
    },

    // 车系下拉框改变时
    changeChexSelect(id) {
      this.clearFormItem(this.topFilterList.find(x => x.fieldName === 'model'));
      if (!id) return;
      this.getCheModelSelect(this.brandCode, id);
    },

    // 清空下拉框表当控件的值和下拉列表
    clearFormItem(item) {
      item.initialValue = undefined;
      item.itemList = [];
    },

    getBusiness(val) {
      if (val.dataBeginDate && val.dataEndDate) {
        let beginDate = moment(val.dataBeginDate).format('YYYY-MM-DD');
        let endDate = moment(val.dataEndDate).format('YYYY-MM-DD');
        val.dataBeginDate = beginDate;
        val.dataEndDate = endDate;
      }
      if (val.checkPreDeliverVehicleBeginDate && val.checkPreDeliverVehicleEndDate) {
        let beginDate = moment(val.checkPreDeliverVehicleBeginDate).format('YYYY-MM-DD');
        let endDate = moment(val.checkPreDeliverVehicleEndDate).format('YYYY-MM-DD');
        val.datcheckPreDeliverVehicleBeginDateaBeginDate = beginDate;
        val.checkPreDeliverVehicleEndDate = endDate;
      }

      this.fetchParams = Object.assign({}, val, { xhrAbort: false, roStatus: val.roStatus ? val.roStatus.join("','") : '' });
    },

    repairLabour(row) {
      this.selectData = row;
      this.labour = true;
    },
    collapseHandle() {
      this.$nextTick(() => {});
    },

    closeDialog() {
      this.labour = false;
    },

    async orderClick() {
      if (this.selectColumns.length) {
        const roNo = this.selectColumns[0].RO_NO;
        const res = await unLockRepairOrder(roNo);
        if (res.resultCode === 200) {
          this.$notify({
            title: '操作结果',
            message: res.data + '!',
            type: 'success'
          });
        }
      } else {
        this.$notify({
          title: '操作结果',
          message: '请先单击选中一条记录！',
          type: 'error'
        });
      }
    },
    // 日志
    orderLogClick() {
      if (this.selectColumns.length) {
        this.orderLog = true;
      } else {
        this.$notify({
          title: '操作结果',
          message: '请先单击选中一条记录！',
          type: 'error'
        });
      }
    },

    // 关闭日志
    closeOrderLog() {
      this.orderLog = false;
    },

    // 导出
    exportClick() {
      repairBussinessExportExcel(this.fetchParams).then(res => {
        exportExcelFile(res, '维修业务查询');
      });
    },

    // 获取系统默认参数
    async getSystemDefaultValueInfo() {
      let params = { itemCode: 1063 };
      let res = await getSystemDefault(params);
      this.systemDefalutParams.yjcylTime = res.data; //  预交车预留时间
      this.systemDefalutParams.orderStatus = (await getSystemDefault({ itemCode: 8033 })).data; // 判断一车一单
      // if (this.systemDefalutParams.orderStatus == '10041001') {
      //   this.columns.find(x => x.dataIndex === 'FD_STATUS').hidden = false;
      //   this.columns.find(x => x.dataIndex === 'EFW_CARD').hidden = false;
      //   this.columns.find(x => x.dataIndex === 'REMARK1').hidden = false;
      // }
    },

    // 获取表格所有数据
    async syncDataChange(val) {
      // 在修天数：竣工时间减去开单时间 在修天数5-9天：黄色 大于10天：浅红色
      // f8eb1a 黄色 FBE1E3红色

      val.forEach(x => {
        x.IS_CLAIM = x.IS_CLAIM == 1004 ? '是' : '否';
        if (x.COMPLETE_TIME) {
          let timeDiff = moment(x.COMPLETE_TIME).diff(moment(x.RO_CREATE_DATE), 'days');
          if (timeDiff >= 5 && timeDiff <= 9) {
            this.styleList.push({ row: x, styles: { backgroundColor: '#f8eb1a' } });
          } else if (timeDiff >= 10) {
            this.styleList.push({ row: x, styles: { backgroundColor: '#FBE1E3' } });
          }
        }
      });
    },
    // 是否扩展查询禁用表单部分字段
    exQueryBtnState(val) {
      console.log(val);
      let disabled = val == 0;
      let changedField = ['address', 'zipCode', 'eMail', 'haveClaimTag', 'PROVINCE', 'CITY', 'DISTRICT'];
      this.topFilterList.forEach(item => {
        if (changedField.includes(item.fieldName)) {
          item.disabled = disabled;
          val == 0 && (item.initialValue = '');
        }
      });
    },
    // 验证系统参数状态并做相应设置
    checkSystemOptionAuthParams() {
      // 是否可以导出excel
      if (this.systemOptionAuthParams.isCanExportExcel === '10041002') {
        this.btnExportType = false;
      }
    },
    // 查询所有人员(翻译结算员)
    async queryAllUser() {
      let res = await getAllUser();
      if (res.resultCode == 200) {
        let userList = res.data.map(item => ({
          text: item.employeeName,
          value: item.userId + ''
        }));
        this.columns.find(item => item.dataIndex === 'BALANCE_HANDLER').dictItems = userList;
      }
    },
    // 查询服务参数
    async queryRepairParams() {
      let res = await findAllRepair();
      if (res.resultCode == 200) {
        this.repairParams = res.data;
      }
    },
    async getProvine() {
      const res = await getProvince();
      this.topFilterList.find(item => item.fieldName === 'PROVINCE').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    },

    // 省份改变
    async provinceChange(regionId) {
      this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'CITY'));
      this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'DISTRICT'));
      if (!regionId) return;
      const res = await getCitys(regionId);
      this.topFilterList.find(item => item.fieldName === 'CITY').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    },

    // 市改变
    async cityChange(regionId) {
      this.clearFormItem(this.topFilterList.find(item => item.fieldName === 'DISTRICT'));
      if (!regionId) return;
      const res = await getDistrict(regionId);
      this.topFilterList.find(item => item.fieldName === 'DISTRICT').itemList = res.data.map(x => ({ value: x.regionId, text: x.regionName }));
    },
    // 导出
    async repairBusinessExport() {
      await repairBusinessExport(this.fetchParams).then(res => {
        console.log(res);
        if (res.status !== 'failure') {
          exportExcelFile(res.data, '维修业务查询导出');
        } else {
          notifyAction('导出失败', 'error');
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
p {
  font-size: 14px;
  // padding-top: 24px;
  color: #ed6b75;
}
</style>
